﻿// Copyright (c) Kona Framework Team. All rights reserved.
// For continued development and updates, visit http://www.codeplex.com/kona
// For a copy of the license please vist: http://www.codeplex.com/kona/license
using System;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Kanaka.ResourceAccess;
using Kanaka.ResourceAccess.Reports;

namespace Kanaka.Website
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UsCustomerCountsByStateReport Report = new UsCustomerCountsByStateReport(2004);
            StateCountRepeater.DataSource = Report.StateProvinceMonthlyCustomerCounts;
            StateCountRepeater.DataBind();
        }

        protected void StateCountRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                StateProvinceMonthlyCustomerCounts Row = e.Item.DataItem as StateProvinceMonthlyCustomerCounts;
                HtmlTableCell StateNameCell = e.Item.FindControl("StateNameCell") as HtmlTableCell;
                StateNameCell.InnerText = Row.StateProvince.Caption;
                Repeater MonthlyCountRepeater = e.Item.FindControl("MonthlyCountRepeater") as Repeater;
                MonthlyCountRepeater.DataSource = Row.MonthlyCustomerCounts;
                MonthlyCountRepeater.DataBind();
            }
        }

        protected void MonthlyCountRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                MonthlyCustomerCount Row = e.Item.DataItem as MonthlyCustomerCount;
                HtmlTableCell MonthlyCountCell = e.Item.FindControl("MonthlyCountCell") as HtmlTableCell;
                MonthlyCountCell.InnerText = Row.Count.ToString("N0",
                                                       System.Globalization.CultureInfo.CreateSpecificCulture("en-US")); ;
            }
        }
    }
}
